package shop.up.all.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import shop.up.common.result.Result;
import shop.up.item.client.ItemFeignClient;

import javax.annotation.Resource;
import java.util.Map;

/**
 * TODO {@link ItemController}
 *
 * @author Kevin
 * @date 2023/2/18
 */
@Controller
public class ItemController {


    @Resource
    private ItemFeignClient itemFeignClient;

    /**
     * sku详情页面
     *  http://item.up.shop/50.html
     * @param skuId
     * @param model
     * @return
     */
    @RequestMapping("{skuId}.html")
    public String getItem(@PathVariable Long skuId, Model model){
        // 通过skuId 查询skuInfo
        Result<Map> result = itemFeignClient.getItem(skuId);
        // 将查询出数据添加到页面模型对象中
        model.addAllAttributes(result.getData());
        // 返回页面
        // templates/item/index.html
        return "item/index";
    }


}
